package org.flashamaphone.voices
{
	import org.flashamaphone.voices.waveformFactories.IWaveFactory;
	
	public class FrequencyModulation extends SimpleWaveform
	{
		protected var envelope:Array = [0,5,1,3,0];
		
		public function FrequencyModulation(waveformFactory:IWaveFactory=null)
		{
			super(waveformFactory);
		}
	}
	
	/**
	 * get attack bytes
	 * 
	 * @param frequency
	 * @param duration (milliseconds)
	 * @return sound byteArray
	 */
	public override function attack(freq:Number, milliseconds:Number):ByteArray {
		var returnBytes:ByteArray = new ByteArray();
		var numSamples:int = (milliseconds * SoundConstants.SAMPLING_RATE_MILLISECONDS);
		returnBytes = wave.cycle(freq, numSamples, wave.lastSampleIndex, envelope[0], envelope[1]);
		return returnBytes;
	}
	
	/**
	 * get decay bytes
	 * 
	 * @param frequency
	 * @param duration (milliseconds)
	 * @return sound byteArray
	 */
	public override function decay(freq:Number, milliseconds:Number):ByteArray {
		var returnBytes:ByteArray = new ByteArray();
		var numSamples:int = (milliseconds * SoundConstants.SAMPLING_RATE_MILLISECONDS);
		returnBytes = wave.cycle(freq, numSamples, wave.lastSampleIndex, envelope[1], envelope[2]);
		return returnBytes;
	}
	
	/**
	 * get sustain bytes
	 * 
	 * @param frequency
	 * @param duration (milliseconds)
	 * @return sound byteArray
	 */
	public override function sustain(freq:Number, milliseconds:Number):ByteArray {
		var returnBytes:ByteArray = new ByteArray();
		var numSamples:int = (milliseconds * SoundConstants.SAMPLING_RATE_MILLISECONDS);
		returnBytes = wave.cycle(freq, numSamples, wave.lastSampleIndex, envelope[2], envelope[3]);
		return returnBytes;
	}
	
	/**
	 * get release bytes
	 * 
	 * @param frequency
	 * @param duration (milliseconds)
	 * @return sound byteArray
	 */
	public override function release(freq:Number, milliseconds:Number):ByteArray {
		var returnBytes:ByteArray = new ByteArray();
		var numSamples:int = (milliseconds * SoundConstants.SAMPLING_RATE_MILLISECONDS);
		returnBytes = wave.cycle(freq, numSamples, wave.lastSampleIndex, envelope[3], envelope[4]);
		return returnBytes;
	}
}